//
//  UserAccountCell.m
//  CheekiOS
//
//  Created by mac on 2017/6/21.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "UserAccountCell.h"
@interface UserAccountCell()

@property (nonatomic, strong) UIImageView *imgView;
@property (nonatomic, strong) UILabel *numberLab;
@property (nonatomic, strong) UILabel *rewardLab;
@property (nonatomic, strong) UIButton *numBtn;
@property (nonatomic, strong) UILabel *linLab;
@property (nonatomic, strong) NSIndexPath *indexPath;

@end
@implementation UserAccountCell

+ (instancetype)cellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath*)indexPath {
    static NSString *UserAccountCellIdent = @"UserAccountCellIdent";
    UserAccountCell * cell = [tableView dequeueReusableCellWithIdentifier:UserAccountCellIdent];
    if (!cell) {
        cell = [[UserAccountCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:UserAccountCellIdent];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.indexPath = indexPath;
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.imgView = [[UIImageView alloc] init];
        [self addSubview:self.imgView];
        
        self.numberLab = [[UILabel alloc] init];
        self.numberLab.font = FontP(16);
        self.numberLab.textColor = [UIColor blackColor];
        [self addSubview:self.numberLab];
        
        self.rewardLab = [[UILabel alloc] init];
        self.rewardLab.font = FontP(16);
        self.rewardLab.textColor = ColorI(0x5978b6);
        [self addSubview:self.rewardLab];
        
        self.numBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.numBtn.layer setMasksToBounds:YES];
        [self.numBtn.layer setBorderWidth:1.0]; //边框宽度
        self.numBtn.layer.borderColor=Colorbackground.CGColor;
        self.numBtn.titleLabel.font = FontP(16);

        [self.numBtn setTitleColor:Colorbackground forState:UIControlStateNormal];
        [self addSubview:self.numBtn];
        
        self.linLab = [[UILabel alloc] init];
        self.linLab.backgroundColor = RGB(243, 243, 243);
        [self addSubview:self.linLab];

        
    }
    return self;
}

-(void)setFirstCharge:(NSString *)firstCharge{
    
    _firstCharge = firstCharge;
    

}
-(void)setNumberArray:(NSArray *)numberArray {

    _numberArray = numberArray;
    

    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(50);
        make.height.with.mas_equalTo(15);
        make.top.equalTo(self.mas_centerY).offset(-7.5);
    }];
    
    
    [self.numberLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imgView.mas_right).offset(7);
        make.height.with.mas_equalTo(15);
        make.top.equalTo(self.mas_centerY).offset(-7.5);
    }];
  

    [self.rewardLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.numberLab.mas_right).offset(13);
        make.height.with.mas_equalTo(15);
        make.top.equalTo(self.mas_centerY).offset(-7.5);

    }];
    
    [self.linLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(50);
        make.right.equalTo(self).offset(-50);
        make.height.mas_equalTo(1);
        make.bottom.equalTo(self).offset(1);
    }];
    
    self.imgView.image = [UIImage imageNamed:@"grzx_account_diamond_icon"];
    
    
    if (_indexPath.row == 0) {
        if ([_firstCharge isEqualToString:@"0"]) {
            
            self.rewardLab.text = [NSString stringWithFormat:@"+30钻石（首充奖励）"];
            
        }else{
            self.rewardLab.text = @"";
            
        }
    }
    

    self.numberLab.text = numberArray[_indexPath.row];
    

}



-(void)setNumberMoneyArray:(NSArray *)numberMoneyArray{
    
    [self.numBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-50);
        make.height.with.mas_equalTo(20);
        make.top.equalTo(self.mas_centerY).offset(-10);
        make.width.mas_equalTo(50);
    }];
    
    [self.numBtn.layer setCornerRadius:10.0];
    
    [self.numBtn setTitle:[NSString stringWithFormat:@"￥%@",numberMoneyArray[_indexPath.row]] forState:UIControlStateNormal];
    
    self.numBtn.tag = _indexPath.row;
    
    [self.numBtn addTarget:self action:@selector(numBtnClickAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
}

- (void)numBtnClickAction:(UIButton *)sender{
    if ([self.delegate respondsToSelector:@selector(numBtnClickAction:)]) {
        [self.delegate numBtnClickAction:sender];
    }
}
@end
